function w = weightsNI(d)

       global n priorvar Cbar1 Cbar0 Vtilde1 Vtilde0 Sigma1 Sigma0
       global xbarNI XNI   
    
   
       n1=sum(d);
       w1=zeros(n,1);
       w2=zeros(n,1);
       
       Ky1=Vtilde1(d==1, d==1) + diag(Sigma1(d==1));
       Ky0=Vtilde0(d==0, d==0) + diag(Sigma0(d==0));
       
       X1=XNI(logical(d),:);
       X0=XNI(logical(1-d),:);
       
       Ky1BSX= Ky1 \ X1;
       Ky0BSX= Ky0 \ X0;
       
       w1(logical(d),:)   = xbarNI(:)' * ((X1' * Ky1BSX) \ Ky1BSX');
       w1(logical(1-d),:) = -xbarNI(:)' * ((X0' * Ky0BSX) \ Ky0BSX');       
       
       w2(logical(d),:)   =  (Cbar1(d==1) / Ky1)*(eye(n1)     -   X1* ((X1' * Ky1BSX) \ Ky1BSX'));
       w2(logical(1-d),:) = -(Cbar0(d==0) / Ky0)*(eye(n - n1) -   X0* ((X0' * Ky0BSX) \ Ky0BSX'));       
       
        
       
       w = w1 + w2;
   
   
return
